package com.xrz.sxm.aj.activity;

import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.TextView;

import com.lidroid.xutils.view.annotation.ViewInject;
import com.xrz.sxm.aj.base.BaseAct;
import com.xrz.sxm.aj.entity_tab.DBHelps;
import com.xrz.sxm.aj.entity_tab.Xwmxb;
import com.xrz.sxm.aj.utils.Utils;
import com.xrz.sxm.aj.view.MyTouchImageView;

import java.util.ArrayList;
import java.util.List;

import me.next.tagview.TagCloudView;

/**
 * Created by Administrator on 2016/9/5.
 */
public class Act_Search_xuewei extends BaseAct implements TagCloudView.OnTagClickListener, View.OnClickListener{
	private DBHelps dbHelps;
	/** 搜索框 */
	@ViewInject(R.id.edt_bing)
	private AutoCompleteTextView edt_bing;
	/** 搜素关键词列表 */
	private List<String> m_Search_keys = new ArrayList<String>();
	/** popup的适配器 */
	private ArrayAdapter<String> m_Search_Adapter;

	@ViewInject(R.id.tag_cloud_view)
	private TagCloudView tagCloudView;
	private List<String> mathXuewei;
	@ViewInject(R.id.xwimageview)
	private MyTouchImageView xwimageview;
	@ViewInject(R.id.tv_empty)
	private TextView tv_empty;
	/**
	 * 设置ContentView
	 */
	@Override
	protected int setView() {
		return R.layout.layout_search_xuewei;
	}

	/**
	 * 功能：初始化信息
	 */
	@Override
	protected void init() {
		dbHelps = new DBHelps(this);
		m_Search_keys = dbHelps.getAllXuewei();
		m_Search_Adapter = new ArrayAdapter<String>(ctx, R.layout.list_item_1,
				m_Search_keys);
		edt_bing.setAdapter(m_Search_Adapter);
		mathXuewei = dbHelps.getMathXuewei();
		tagCloudView.setTags(mathXuewei);
		tagCloudView.setOnTagClickListener(this);
		findViewById(R.id.tv_search).setOnClickListener(this);
	}

	/**
	 * 设置顶部菜单的标题
	 */
	@Override
	protected String setTopTitle() {
		return "搜索穴位";
	}

	@Override
	public void onTagClick(int position) {
		edt_bing.setText("");
		String xuwei = mathXuewei.get(position);
		List<Xwmxb> list = dbHelps.getPicnameByXueweiName(xuwei);
		if(list != null && list.size() != 0){
			Xwmxb xwmxb = list.get(0);
			int resid = Utils.getImageByPicName(xwmxb.tmlj);
			xwimageview.setImageResource(resid);
			tv_empty.setText(xwmxb.qxms);
		}else{
			tv_empty.setText("暂无穴位信息~");
		}
	}

	@Override
	public void onClick(View view) {
		switch(view.getId()){
			case R.id.tv_search:
				String text = edt_bing.getText().toString().trim();
				List<Xwmxb> list = dbHelps.getPicnameByXueweiName(text);
				if(list != null && list.size() != 0){
					Xwmxb xwmxb = list.get(0);
					int resid = Utils.getImageByPicName(xwmxb.tmlj);
					xwimageview.setImageResource(resid);
					tv_empty.setText(xwmxb.qxms);
				}else{
					tv_empty.setText("暂无穴位信息~");
				}
				break;
		}
	}
}
